<template>

  <!-- 添加或修改盘点计划对话框 -->
  <el-dialog :title="title" v-if="open" v-model="open" width="600px" append-to-body>
    <el-form ref="form" :model="form" :rules="rules" label-width="90px" v-loading="loading">
      <el-form-item label="价格名称:" prop="dictLabel">
        <el-input v-model="form.dictLabel"></el-input>
      </el-form-item>
    </el-form>

    <template #footer>
      <div class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submitForm">确定</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script>
import { customAdddictLabel } from '@/api/goods/goods';
export default {
  name: "addForm",
  data() {
    return {
      open: false,
      title: "添加自定义单位价格",
      form: {},
      loading: false,
      rules: {
        dictLabel: [
          { required: true, message: "价格名称不能为空", trigger: "blur" }
        ],
      },
    }
  },
  created() {
  },
  methods: {
    add() {
      this.open = true;
      this.form = {};
      this.$nextTick(() => {
        this.$refs.form.clearValidate()
      })
    },
    cancel() {
      this.open = false;
    },
    submitForm() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.loading = true;
          customAdddictLabel(this.form).then(res => {
            if (res.code == 200) {
              this.loading = false;
              this.open = false;
              this.$emit('ok');
            } else {
              this.$modal.msgError(res.msg)
            }
          }).catch(err => {
            this.loading = false;
          })
        } else {
          return false;
        }
      });
    }
  }
}
</script>

<style lang="scss" scoped></style>